<?php
if(ipsRegistry::$request['request_method'] == 'get')
{
	ipsRegistry::DB()->build(array('select'=>'*','from'=>'market_bank_accounts','where'=>"a_interest_time+a_last_interest < ".IPS_UNIX_TIME_NOW));
	$q = ipsRegistry::DB()->execute();
	while($account = ipsRegistry::DB()->fetch($q))
	{
		$new_balance = numbers::round(numbers::multiply($account['balance'],1+$account['interest_rate']/100));
		$increase = numbers::subtract($new_balance,$account['balance']);
		ipsRegistry::DB()->update('market_bank_accounts',array(
																'balance' => $new_balance,
																'a_last_interest' => $account['a_last_interest'] + $account['a_interest_time'],
							),"account_id=".$account['account_id']);
		ipsRegistry::DB()->insert('market_bank_transactions',array(
																	'l_account_id' => sprintf("%08d-%06d-%06d",$account['a_mem_id'],$account['a_random'],$account['account_id']),
																	'l_timestamp' => $account['a_last_interest'] + $account['a_interest_time'],
																	'l_ip_address' => ips_MemberRegistry::instance()->ip_address,
																	'l_action' => 'interest',
																	'l_amount' => $increase,
																	'l_balance' => $new_balance,
																	'l_fee' => 0,
								)								);
	}
}
?>